package com.imau.controller;

import com.imau.util.CheckCodeUtil;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/checkCode")
public class CheckCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ServletOutputStream outputStream = response.getOutputStream();


        String checkCode = CheckCodeUtil.outputVerifyImage(100, 50, outputStream, 4);


        // 将验证码保存到session中，验证码的比对是和session中保存的验证码进行比对

        HttpSession session = request.getSession();
        session.setAttribute("checkCode", checkCode);

        System.out.println(checkCode);
    }
}
